<?php

namespace Modules\WeChat\Http\Controllers;

use HiCommon\Service\OrderCheckpointService;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Request;
use Modules\Api\Service\CheckpointOrderService;

class OrderController extends Controller
{

    /**
     * 检测站-已完成预约订单-商家
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function order_checkpoint_list()
    {
        try {
            $arr_input = Request::input();
            $arr_admin_user = wechat_user();
            $n_shop_id = intval($arr_admin_user['shop']['id']);
            $res = CheckpointOrderService::api_complete_order_list_by_shopid($n_shop_id, $arr_input);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }

    }

    /**
     * 检测站-待处理预约订单-商家
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function deal_order_checkpoint_list()
    {
        try {
            $arr_input = Request::input();
            $arr_admin_user = wechat_user();
            $n_shop_id = intval($arr_admin_user['shop']['id']);
            $res = CheckpointOrderService::api_waiting_order_list_by_shopid($n_shop_id, $arr_input);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }

    }

    /**
     * 年检预约订单 - 检测完成(全部车)
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function order_checkpoint_complete_all()
    {
        try {
            $n_id = Request::input('id', 0);
            $arr_admin_user = wechat_user();
            $n_shop_id = intval($arr_admin_user['shop']['id']);
            shiwu_start();
            $res = OrderCheckpointService::api_deal_complete_all($n_id, $n_shop_id);
            shiwu_end($res);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 年检预约订单 - 检测完成(单辆车)
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function order_checkpoint_complete_single()
    {
        try {
            $n_id = Request::input('id', 0);
            $arr_admin_user = wechat_user();
            $n_shop_id = intval($arr_admin_user['shop']['id']);
            shiwu_start();
            $res = OrderCheckpointService::api_deal_complete_single($n_id, $n_shop_id);
            shiwu_end($res);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 年检预约订单 - 检测失败(单辆车-退款)-操作
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function order_checkpoint_fail_single()
    {
        try {
            $n_id = Request::input('id', 0);
            $arr_admin_user = wechat_user();
            $n_shop_id = intval($arr_admin_user['shop']['id']);
            $s_remark = trim(Request::input('remarks', ''));
            $s_fail_type = trim(Request::input('fail_type', ''));
            shiwu_start();
            $res = OrderCheckpointService::api_deal_fail_single($n_id, $n_shop_id, $s_remark, $s_fail_type);
            shiwu_end($res);
            return $res;
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }
}
